//
//  WMH_NewsDetailView.m
//  iphone.mobileoa
//
//  Created by 李林 on 13-10-24.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//  新闻详情

#import "WMH_NewsDetail_ViewController.h"

#import "EpointAppDelegate.h"

#import "UIViewController+MJPopupViewController.h"

#define getNewsDetailTaskId 1

#import "WMH_NewsUrlDetail_ViewController.h"

@interface WMH_NewsUrlDetail_ViewController ()

@end

@implementation WMH_NewsUrlDetail_ViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        _appDelegate = (EpointAppDelegate *)[UIApplication sharedApplication].delegate;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //获取传入的参数
    InfoID      = [self.passParam objectForKey:@"InfoID"];
    CateNum     = [self.passParam objectForKey:@"CateNum"];
    IsNeedUrl   = [self.passParam objectForKey:@"IsNeedUrl"];
    
    //获取详情
    [self getNewsDetailData];
    
}

-(IBAction)clickMenu2{
    NSString *title = [NSString stringWithFormat:@"//分享:%@",infoTitle];
//    [self toSharedAction:@"" withURL:shareURL withImage:nil];
}

-(IBAction)clickMenu1{
    
}

//-(IBAction)toSharedAction:(NSString *) title  withURL:(NSString*)url withImage:(NSString *)imgpath{
//    id<ISSCAttachment> imageAttach= nil;
//    NSString * shareMsg=nil;
//    SSPublishContentMediaType mediaType = SSPublishContentMediaTypeText;
//    if (imgpath==nil) {
//        shareMsg=[NSString stringWithFormat:@"%@ %@",title,url];
//        mediaType = SSPublishContentMediaTypeText;
//    }else{
//        NSLog(@"imgPath=%@",imgpath);
//        shareMsg=[NSString stringWithFormat:@"%@",title];
//        imageAttach = [ShareSDK imageWithPath:imgpath];
//        mediaType = SSPublishContentMediaTypeImage;
//    }
//    
//    //构造分享内容
//    id<ISSContent> publishContent=[ShareSDK content:shareMsg
//                                     defaultContent:@"默认分享内容,没内容时显示"
//                                              image:imageAttach title:@"分享"
//                                                url:@"" description:@"分享" mediaType:mediaType];
//    //定义菜单分享列表
//    NSArray *shareList = [ShareSDK getShareListWithType:  ShareTypeSinaWeibo, ShareTypeTencentWeibo,ShareTypeWeixiSession,ShareTypeWeixiTimeline,ShareTypeQQSpace,ShareType163Weibo,ShareTypeRenren ,ShareTypeSMS,ShareTypeMail,nil];
//    //创建分享选项
//    id<ISSShareOptions> shareOptions = [ShareSDK defaultShareOptionsWithTitle:@"分享" oneKeyShareList:shareList qqButtonHidden:YES wxSessionButtonHidden:YES wxTimelineButtonHidden:YES showKeyboardOnAppear:NO shareViewDelegate:_appDelegate.viewDelegate friendsViewDelegate:_appDelegate.viewDelegate picViewerViewDelegate:nil];
//    
//    id<ISSAuthOptions> authOptions = [ShareSDK authOptionsWithAutoAuth:YES
//                                                         allowCallback:YES
//                                                         authViewStyle:SSAuthViewStyleFullScreenPopup
//                                                          viewDelegate:nil
//                                               authManagerViewDelegate:_appDelegate.viewDelegate];
//    
//    [ShareSDK showShareActionSheet:nil shareList:shareList
//                           content:publishContent statusBarTips:YES authOptions :authOptions shareOptions:shareOptions
//                            result:^(ShareType type, SSPublishContentState state, id<ISSStatusInfo> statusInfo,id<ICMErrorInfo>error,BOOL end){
//                                if (state == SSPublishContentStateSuccess)
//                                {
//                                    NSLog(@"分享成功");
//                                }
//                                
//                                else if (state == SSPublishContentStateFail) {
//                                    NSLog(@"分享失败,错误码:%d,错误描述:%@", [error errorCode],[error errorDescription]);
//                                } }];
//    
//    
//}

#pragma mark 获取新闻详情
- (void)getNewsDetailData
{
    [self showMBPHUD];
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:InfoID    forKey:@"InfoID"];
    [params setObject:CateNum   forKey:@"CateNum"];
    [params setObject:IsNeedUrl forKey:@"IsNeedUrl"];
    [params setObject:@"0"      forKey:@"isvideo"];
    [params setObject:@"320"    forKey:@"imgwidth"];
    [self startTask:@"Task_GetInfoDetail" withParams:params withTaskId:getNewsDetailTaskId];}

#pragma mark 刷新UI
-(void)refreshUIWithThreadGuid:(int)taskId andData:(NSObject *)obj
{
    [self hideMBPHUD];//关闭滚动条
    
    if (taskId==getNewsDetailTaskId) {
        [self dealNewsDetailData:obj];
    }
}

#pragma mark 处事新闻详情数据
-(void)dealNewsDetailData:(NSObject *)obj{
    
    
    //处理异常信息
    NSMutableArray *arr = (NSMutableArray*)obj;
    if (![[arr objectAtIndex:0]isEqualToString:@"1"]) {
        [self toastMessage:[arr objectAtIndex:1]];
        return;
    }
    

    NSString *result = [arr objectAtIndex:2];
    

    result =[result stringByReplacingOccurrencesOfString:@"<![CDATA[" withString:@""];
    result= [result stringByReplacingOccurrencesOfString:@"]]>" withString:@""];
    NSString *urlstr = [EpointStringUtil getXMLFormatedAttribute :result :@"url"];
    NSURL *url = [[NSURL alloc]initWithString:urlstr];
    shareURL = [EpointStringUtil getXMLFormatedAttribute :result :@"weburl"];
    [self.mWebView loadRequest:[NSURLRequest requestWithURL:url]];
    self.mWebView.delegate = self;
}



@end

